<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of LoginModel
 *
 * @author nstevens
 */
include_once 'model/commonModel.php';

class LoginModel extends commonModel {

    public $string;

    public function __construct() {
        
    }

    /*
     * Processes a log in request and send the user to their homepage based on their role
     */
    public function processLogin() {
        $output = "";
        if (strcmp($_SESSION['role'], "pi") === 0) {
            $output .= getNewHtmlUpToMeta();
            $output .= getMantisCSSLine();
            $output .= getTitle("PI Main");
            $output .= getCloseTag("head");
            $output .= getOpenTag("body");
            $output .= getLogoLine();
            $output .= getLoggedInAsLine();
            $output .= getPiMenu();
            $output .= '<br><br>';
            $result = executeSelect("SELECT * FROM requirement ORDER by fiscalYear ASC, priority ASC");
            $output .= getRequirementsTable($result, false);
            $output .= '<br>';
            $output .= getCloseTag("body");
            $output .= getCloseTag("html");
        } else if (strcmp($_SESSION['role'], "admin") === 0) {
            $output .= getUpToMainMenu(getUserRole(), "Admin Main");
            $output .= '<br><br>';
            $result = executeSelect("SELECT * FROM requirement ORDER by fiscalYear ASC, priority ASC");
            $output .= getRequirementsTable($result, false);
            $output .= getCloseTag("body");
            $output .= getCloseTag("html");
        } else if (strcmp($_SESSION['role'], "pireviewer") === 0) {
            $output .= getUpToMainMenu(getUserRole(), "PI Reviewer Main");
            $output .= '<br><br>';
            $result = executeSelect("SELECT * FROM requirement ORDER by fiscalYear ASC, priority ASC");
            $output .= getRequirementsTable($result, false);
            $output .= getCloseTag("body");
            $output .= getCloseTag("html");
        } else if (strcmp($_SESSION['role'], "piapprover") === 0) {
            $output .= $this->getPIApproverMainPage();
        } else if (strcmp($_SESSION['role'], "cnmocUser") === 0) {
            $output .= getUpToMainMenu(getUserRole(), "CNMOC User Main");
            $output .= getCloseTag("body");
            $output .= getCloseTag("html");
            echo '<br><br>';
            $result = executeSelect("SELECT * FROM requirement ORDER by fiscalYear ASC, priority ASC");
            $output .= getRequirementsTable($result, false);
        } else {
            header("location:unknownRole.php");
        }
        return $output;
    }

    function getPIApproverMainPage() {
        $output = "";
        $output .= $this->getBasicHeader("Main Page");
        $output .= '<br><br> ' . getWebmasterFeedbackForm();
        $output .= getCloseTag("body");
        $output .= getCloseTag("html");
        return $output;
    }
}

?>
